package com.android.task4;

public abstract class Projection {
	public static double Clip(final double n, final double minValue,
			final double maxValue) {
		return Math.min(Math.max(n, minValue), maxValue);
	}

	public abstract int latToY(final double latitude, final int zoomLevel);

	public abstract int lonToX(final double longitude, final int zoomLevel);

	public abstract double yToLat(final int y, final int zoomLevel);

	public abstract double xToLon(final int x, final int zoomLevel);

	public Point coordinatesToPoint(final Coordinates coordinates,
			final int zoomLevel) {
		return new Point(lonToX(coordinates.getLongitude(), zoomLevel), latToY(
				coordinates.getLatitude(), zoomLevel));
	}

	public Coordinates pointToCoordinates(final Point point, final int zoomLevel) {
		return new Coordinates(yToLat(point.getY(), zoomLevel), xToLon(point
				.getX(), zoomLevel), 0);
	}
}
